//package personal.abandoned;
//
//import personal.scanner.ScannerFiniteAutomata;
//
//import java.util.Set;
//
///**
// * 将正则表达式转化成最小化的 DFA
// *
// * @author 陈渤林
// */
//public class ExREToMinDFAConverter {
////	/** 临时测试程序 */
////	public static void main(String[] args) {
////		Set<Integer> transitions = new HashSet<Integer>();
////		for (int i = 0; i < 128; ++i)
////			transitions.add(i);
//////		String re = "++|+|[|];|\\(|\\)|.|\\->|\\-|~|\\-\\-|\\*|&|!|sizeof\\(|/|\\*|%|\\-|<<|>>|>|>=|<|<=|==|!=|&|^|\\||&&|\\|\\||?:|=|/=|\\*=|%=|+=|\\-=|<<=|>>=|&=|^=|\\|=|,";
////		String re = "++|+|\\(";
////		FiniteAutomata ans = new REToMinDFAconverter().convert(re, transitions, 2, 1);
//////		try (FileOutputStream fout = new FileOutputStream("./data/output.md")) {
//////			fout.write(ans.toMermaid().getBytes()); // 文件输出
//////		} catch (Exception e) {
//////		}
////		ans.init();
////		System.out.println(TestDrive.check(ans, "++"));
////	}
//
//    private Set<Integer> transitions = null;
//
//    /**
//     * 辅助函数，将 nfa 转换成 mindfa
//     */
//    private ScannerFiniteAutomata NFAToMinDFA(ScannerFiniteAutomata nfa, int start_id) {
//        ScannerFiniteAutomata dfa = new NFAToDFAConverter().convert(nfa, this.transitions, start_id); // nfa 转 dfa
//        ScannerFiniteAutomata mindfa = new DFAMinimizer().minimize(dfa, this.transitions, start_id); // 尝试最小化 dfa
//        while (mindfa.getSize() < dfa.getSize()) { // 可以进一步优化
//            dfa = mindfa;
//            mindfa = new DFAMinimizer().minimize(dfa, this.transitions, start_id);
//        }
//        return dfa;
//    }
//
//    /**
//     * 将扩展正则表达式转换成最小化的确定性有限自动机
//     *
//     * @param re        扩展正则表达式
//     * @param accept_id 接受值
//     * @param start_id  自动机开始编号
//     * @return dfa 自动机
//     */
//    public ScannerFiniteAutomata convert(String re, int accept_id, int start_id) {
//        StREToNFAConverter stREToNFAConverter = new StREToNFAConverter();
//        ScannerFiniteAutomata nfa = stREToNFAConverter.convert(re, start_id, accept_id);
//        this.transitions = stREToNFAConverter.getTransitions();
//        nfa = new NFAToDFAConverter().convert(nfa, this.transitions, start_id);
//        return NFAToMinDFA(nfa, start_id);
//    }
//
////	/** 辅助函数，将多个 dfa 合并成 nfa */
////	private FiniteAutomata merge(List<FiniteAutomata> nfas, int start_id) {
////		FiniteAutomata nfa = new FiniteAutomata();
////		// 合并多个 dfa
////		for (int i = 0; i < nfas.size(); ++i) {
////			// 合并边
////			nfa.addEdge(start_id, nfas.get(i).start_id_, FiniteAutomata.empty_trans_);
////			for (int u = 1; u <= nfas.get(i).n_; ++u)
////				for (Node tmp : nfas.get(i).adj_.get(u))
////					nfa.addEdge(u, tmp.v, tmp.w);
////			nfa.accepts_.addAll(nfas.get(i).accepts_); // 合并接受节点
////			nfa.accepts_id_.putAll(nfas.get(i).accepts_id_); // 合并接受值
////		}
////		return nfa;
////	}
//
////	/**
////	 * 将多个扩展正则表达式转换成最小化的确定性有限自动机
////	 *
////	 * @param res         多个扩展正则表达式
////	 * @param transitions 转移表
////	 * @param accept_id   最小的接受值
////	 * @param start_id    状态机的开始 id
////	 * @return dfa 自动机
////	 */
////	FiniteAutomata convert(final List<String> res, final Set<Integer> transitions, int accept_id, int start_id) {
////		// 合并多个 dfa
////		List<FiniteAutomata> dfas = new ArrayList<FiniteAutomata>();
////		int now_id = start_id + 1;
////		for (int i = 0; i < res.size(); ++i) {
////			FiniteAutomata tmp_fa = convert(res.get(i), transitions, accept_id + i, now_id); // 生成 dfa
////			dfas.add(tmp_fa);
////			now_id = tmp_fa.n_ + 1;
////		}
////
////		FiniteAutomata nfa = merge(dfas, start_id);
//////		try (FileOutputStream fout = new FileOutputStream("./data/output.md")) {
//////			fout.write(nfa.toMermaid().getBytes()); // 文件输出
//////		} catch (Exception e) {
//////			System.out.print(nfa.toMermaid());
//////		}
//////		return new NFAToDFAConverter().convert(nfa, transitions, start_id);
////		return NFAToMinDFA(nfa, transitions, start_id);
////	}
//}
